//
//  GoodsList.m
//  RRBI
//
//  Created by kuyuZJ on 16/7/5.
//
//

#import "GoodsList.h"
#import "GoodsListCell.h"

@interface GoodsList ()<GoodsListCellDelegate,UITextFieldDelegate,UIAlertViewDelegate>

@property(nonatomic,copy) NSString* cellIdentifier;

@property(nonatomic,strong) UIView* contentView;
@property(nonatomic,strong) UIImageView* contentBackground;
@property(nonatomic,strong) UILabel* labelTitle;
@property(nonatomic,strong) UIImageView* line;
@property(nonatomic,strong) UILabel* labelSaleTitle;
@property(nonatomic,strong) UILabel* labelSalePrice;
@property(nonatomic,strong) UILabel* labelNewTitle;
@property(nonatomic,strong) UITextField* txtNewPrice;
@property(nonatomic,strong) UILabel* labelTip;
@property(nonatomic,strong) UIButton* btnConfirm;
@property(nonatomic,strong) UIButton* btnCancel;

@property(nonatomic,strong) NSMutableArray* arrayData;
@property(nonatomic,strong) NetPage* page;

@property(nonatomic,strong) MGoods* currentGoods;
@end

@implementation GoodsList

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title =  @"商品管理";
    
    self.cellIdentifier =  @"GoodsListCell";
    [self.tableView registerClass:[GoodsListCell class] forCellReuseIdentifier:self.cellIdentifier];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self layoutUI];
    [self layoutConstraints];
    [self refreshDataSource];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark =====================================================  user interface layout
-(void)layoutUI{
    [self.contentView addSubview:self.contentBackground];
    [self.contentView addSubview:self.labelTitle];
    [self.contentView addSubview:self.line];
    [self.contentView addSubview:self.labelSaleTitle];
    [self.contentView addSubview:self.labelSalePrice];
    [self.contentView addSubview:self.labelNewTitle];
    [self.contentView addSubview:self.txtNewPrice];
    [self.contentView addSubview:self.labelTip];
    [self.contentView addSubview:self.btnConfirm];
    [self.contentView  addSubview:self.btnCancel];
}

-(void)layoutConstraints{
    self.contentBackground.translatesAutoresizingMaskIntoConstraints = NO;
    self.labelTitle.translatesAutoresizingMaskIntoConstraints = NO;
    self.line.translatesAutoresizingMaskIntoConstraints = NO;
    self.labelSaleTitle.translatesAutoresizingMaskIntoConstraints = NO;
    self.labelSalePrice.translatesAutoresizingMaskIntoConstraints = NO;
    self.labelNewTitle.translatesAutoresizingMaskIntoConstraints = NO;
    self.txtNewPrice.translatesAutoresizingMaskIntoConstraints = NO;
    self.labelTip.translatesAutoresizingMaskIntoConstraints = NO;
    self.btnConfirm.translatesAutoresizingMaskIntoConstraints = NO;
    self.btnCancel.translatesAutoresizingMaskIntoConstraints = NO;
    
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.contentBackground attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.contentBackground attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.contentBackground attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.contentBackground attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0.f]];
    
    [self.labelTitle addConstraint:[NSLayoutConstraint constraintWithItem:self.labelTitle attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:30.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.labelTitle attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:10.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.labelTitle attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:10.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.labelTitle attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-10.f]];
    
    [self.line addConstraint:[NSLayoutConstraint constraintWithItem:self.line attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:1.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.line attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.labelTitle attribute:NSLayoutAttributeBottom multiplier:1.0 constant:10.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.line attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:10.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.line attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-10.f]];
    
    [self.labelSaleTitle addConstraint:[NSLayoutConstraint constraintWithItem:self.labelSaleTitle attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:30.f]];
    [self.labelSaleTitle addConstraint:[NSLayoutConstraint constraintWithItem:self.labelSaleTitle attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:60.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.labelSaleTitle attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.line attribute:NSLayoutAttributeBottom multiplier:1.0 constant:10.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.labelSaleTitle attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:10.f]];
    
    [self.labelSalePrice addConstraint:[NSLayoutConstraint constraintWithItem:self.labelSalePrice attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:30.f]];
    [self.labelSalePrice addConstraint:[NSLayoutConstraint constraintWithItem:self.labelSalePrice attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:80.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.labelSalePrice attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.line attribute:NSLayoutAttributeBottom multiplier:1.0 constant:10.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.labelSalePrice attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.labelSaleTitle attribute:NSLayoutAttributeRight multiplier:1.0 constant:10.f]];
    
    [self.labelNewTitle addConstraint:[NSLayoutConstraint constraintWithItem:self.labelNewTitle attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:30.f]];
    [self.labelNewTitle addConstraint:[NSLayoutConstraint constraintWithItem:self.labelNewTitle attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:60.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.labelNewTitle attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.labelSaleTitle attribute:NSLayoutAttributeBottom multiplier:1.0 constant:15.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.labelNewTitle attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:10.f]];
    
    [self.txtNewPrice addConstraint:[NSLayoutConstraint constraintWithItem:self.txtNewPrice attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:30.f]];
    [self.txtNewPrice addConstraint:[NSLayoutConstraint constraintWithItem:self.txtNewPrice attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:100.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.txtNewPrice attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.labelSalePrice attribute:NSLayoutAttributeBottom multiplier:1.0 constant:15.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.txtNewPrice attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.labelNewTitle attribute:NSLayoutAttributeRight multiplier:1.0 constant:10.f]];
    
    [self.labelTip addConstraint:[NSLayoutConstraint constraintWithItem:self.labelTip attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:20.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.labelTip attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.labelNewTitle attribute:NSLayoutAttributeBottom multiplier:1.0 constant:10.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.labelTip attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:10.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.labelTip attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-10.f]];
    
    [self.btnConfirm addConstraint:[NSLayoutConstraint constraintWithItem:self.btnConfirm attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:30.f]];
    [self.btnConfirm addConstraint:[NSLayoutConstraint constraintWithItem:self.btnConfirm attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:80.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.btnConfirm attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-15.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.btnConfirm attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:15.f]];
    
    [self.btnCancel addConstraint:[NSLayoutConstraint constraintWithItem:self.btnCancel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:30.f]];
    [self.btnCancel addConstraint:[NSLayoutConstraint constraintWithItem:self.btnCancel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:80.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.btnCancel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-15.f]];
    [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.btnCancel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.self.contentView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-15.f]];
    
}



#pragma mark =====================================================  Data Source
-(void)queryData{
    
    NSDictionary* arg = @{@"ince":@"get_shop_foods",@"sid":[UserModel sharedInstanced].ru_Id, @"page":[WMHelper integerConvertToString:self.page.pageIndex]};
    NetRepositories* repositories = [[NetRepositories alloc]init];
    [repositories queryGoods:arg page:self.page complete:^(EnumNetResponse react, NSArray *list, NSString *message) {
        if(self.page.pageIndex == 1){
            [self.arrayData removeAllObjects];
        }
        if(react == NetResponseSuccess){
            [list enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [self.arrayData addObject:obj];
            }];
        }else if(react == NetResponseException){
            [self alertHUD:message];
        }else{
            [self alertHUD:message];
        }
        
        [self.tableView reloadData];
        if(self.page.pageCount<=self.page.pageIndex){
            [self.tableView.mj_footer endRefreshingWithNoMoreData];
        }else{
            [self.tableView.mj_footer endRefreshing];
        }
        if(self.page.pageIndex==1){
            [self.tableView.mj_header endRefreshing];
        }
        
    }];
    
}
-(void)refreshDataSource{
    __weak typeof(self) weakSelf = self;
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        weakSelf.page.pageIndex = 1;
        [weakSelf queryData];
    }];
    
    self.tableView.mj_footer = [MJRefreshAutoStateFooter footerWithRefreshingBlock:^{
        weakSelf.page.pageIndex ++;
        [weakSelf queryData];
    }];
    [self.tableView.mj_header beginRefreshing];
}

#pragma mark =====================================================  <UITableViewDataSource>
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arrayData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    GoodsListCell* cell = [tableView dequeueReusableCellWithIdentifier:self.cellIdentifier forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.delegate = self;
    cell.entity = self.arrayData[indexPath.row];
    return cell;
}

#pragma mark =====================================================  <UITableViewDelegate>
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    MGoods* item = self.arrayData[indexPath.row];
    CGFloat width = SCREEN_WIDTH - 150.f;
    CGFloat height = [WMHelper calculateTextHeight:item.goodsName font:[UIFont systemFontOfSize:14.f] width:width];
    if(height>35.f){
        return 35.f+height;
    }
    return 70.f;
}

#pragma mark =====================================================  <GoodsListCellDelegate>
-(void)updateGoodsPrice:(MGoods *)sender{
    if(sender){
        self.currentGoods = sender;
        self.labelSalePrice.text = self.currentGoods.price;
        self.HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
        [self.navigationController.view addSubview:self.HUD];
        self.HUD.delegate = self;
        self.HUD.dimBackground = YES;
        self.HUD.color = [UIColor clearColor];
        self.HUD.mode = MBProgressHUDModeCustomView;
        self.HUD.customView  =self.contentView;
        [self.HUD show:YES];
    }
}
-(void)publishGoods:(MGoods *)sender{
    if(sender){
        self.currentGoods = sender;
        NSString* empty = [NSString stringWithFormat: @"确认%@",[self.currentGoods.status integerValue]==0? @"下架": @"上架"];
        UIAlertView* alert = [[UIAlertView alloc]initWithTitle:empty message:nil delegate:self cancelButtonTitle: @"取消" otherButtonTitles: @"确认", nil];
        [alert show];
    }
}
#pragma mark =====================================================  <UIAlertViewDelegate>
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if(buttonIndex ==1){
        NetRepositories* repositories = [[NetRepositories alloc]init];
        NSString* status = [self.currentGoods.status integerValue]==0? @"1": @"0";
        NSDictionary* arg =  @{@"ince":@"set_shop_foodstatus",@"sid":[UserModel sharedInstanced].ru_Id, @"fid": self.currentGoods.rowID, @"status":status};
        [repositories updtaeGoods:arg complete:^(EnumNetResponse react, NSString *message) {
            if(react == NetResponseSuccess){
                [self alertHUD: @"操作成功!"];
            }else if (react == NetResponseException){
                [self alertHUD:message];
            }else{
                [self alertHUD:message];
            }
            self.currentGoods = nil;
            [self.tableView.mj_header beginRefreshing];
        }];
        
    }
}

#pragma mark =====================================================  <UITextFieldDelegate>
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    NSString *strings = [textField.text stringByReplacingCharactersInRange:range withString:string];
    NSString *str_ =  @"0123456789.\n";
    NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:str_] invertedSet];
    NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
    BOOL basicTest = [string isEqualToString:filtered];
    if (!basicTest) {
        self.labelTip.text =  @"请输入数字";
        return NO;
    }else{
        self.labelTip.text =  @"";
    }
    if ([strings isEqualToString:@"0"]) {
        return NO;
    }
    if (strings.length>0) {
        if([strings hasPrefix: @"."]){
            self.labelTip.text =  @"不能以点开始！";
            return NO;
        }else{
            self.labelTip.text =  @"";
        }
    }
    return YES;
}

#pragma mark =====================================================  SEL
-(IBAction)confirmTouch:(id)sender{
    if([self checkForm] && self.currentGoods){
        NetRepositories* repositories = [[NetRepositories alloc]init];
        NSDictionary* arg =  @{@"ince":@"set_shop_foodprice",@"sid":[UserModel sharedInstanced].ru_Id, @"fid": self.currentGoods.rowID, @"price":self.txtNewPrice.text};
        [repositories netConfirm:arg complete:^(EnumNetResponse react,NSDictionary* response ,NSString *message) {
            if(react == NetResponseSuccess){
                self.labelTip.text = message;
                NSString* price = [response objectForKey: @"price"];
                NSString* checkPrice = [response objectForKey: @"check_price"];
                self.currentGoods.price = price;
                self.currentGoods.checkPrice = checkPrice;
                [self hidHUD];
                self.txtNewPrice.text =  @"";
                [self.tableView reloadData];
            }else if (react == NetResponseException){
                self.labelTip.text = message;
            }else{
                self.labelTip.text = message;
            }
        }];
    }
}

-(IBAction)cancelTouch:(id)sender{
    self.txtNewPrice.text =  @"";
    [self hidHUD];
}

#pragma mark =====================================================  private method
-(BOOL)checkForm{
    if(!(self.txtNewPrice.text.length > 0)){
        self.labelTip.text =  @"价格不能为空";
        return NO;
    }
    
    NSArray* array = [self.txtNewPrice.text componentsSeparatedByString:@"."];
    if(array.count>2){
        self.labelTip.text =  @"商品价格格式不正确";
        return NO;
    }
    
    self.labelTip.text =  @"";
    return YES;
}
#pragma mark =====================================================  property pacakge
-(UIView *)contentView{
    if(!_contentView){
        _contentView = [[UIView alloc]init];
        _contentView.frame = CGRectMake(0, 0, 200, 210);
        _contentView.backgroundColor = [UIColor clearColor];
    }
    return _contentView;
}

-(UIImageView *)contentBackground{
    if(!_contentBackground){
        _contentBackground = [[UIImageView alloc]init];
        [_contentBackground setImage:[UIImage imageNamed: @"bg-store-update"]];
    }
    return _contentBackground;
}

-(UILabel *)labelTitle{
    if(!_labelTitle){
        _labelTitle = [[UILabel alloc]init];
        [_labelTitle setTextColor:[UIColor colorWithRed:125/255.f green:125/255.f blue:125/255.f alpha:1.0]];
        _labelTitle.font =[UIFont systemFontOfSize:14.f];
        _labelTitle.textAlignment = NSTextAlignmentCenter;
        _labelTitle.text =  @"修改价格";
    }
    return _labelTitle;
}

-(UIImageView *)line{
    if(!_line){
        _line = [[UIImageView alloc]init];
        _line.backgroundColor = theme_line_color;
    }
    return _line;
}

-(UILabel *)labelSaleTitle{
    if(!_labelSaleTitle){
        _labelSaleTitle = [[UILabel alloc]init];
        [_labelSaleTitle setTextColor:[UIColor colorWithRed:125/255.f green:125/255.f blue:125/255.f alpha:1.0]];
        _labelSaleTitle.font =[UIFont systemFontOfSize:14.f];
        _labelSaleTitle.textAlignment = NSTextAlignmentRight;
        _labelSaleTitle.text =  @"销售价:";
    }
    return _labelSaleTitle;
}

-(UILabel *)labelSalePrice{
    if(!_labelSalePrice){
        _labelSalePrice = [[UILabel alloc]init];
        [_labelSalePrice setTextColor:[UIColor colorWithRed:125/255.f green:125/255.f blue:125/255.f alpha:1.0]];
        _labelSalePrice.font =[UIFont systemFontOfSize:17.f];
        _labelSalePrice.textAlignment = NSTextAlignmentLeft;
        _labelSalePrice.text =  @"5.70";
    }
    return _labelSalePrice;
}

-(UILabel *)labelNewTitle{
    if(!_labelNewTitle){
        _labelNewTitle = [[UILabel alloc]init];
        [_labelNewTitle setTextColor:[UIColor colorWithRed:125/255.f green:125/255.f blue:125/255.f alpha:1.0]];
        _labelNewTitle.font =[UIFont systemFontOfSize:14.f];
        _labelNewTitle.textAlignment = NSTextAlignmentRight;
        _labelNewTitle.text =  @"修改后:";
    }
    return _labelNewTitle;
}

-(UITextField *)txtNewPrice{
    if(!_txtNewPrice){
        _txtNewPrice = [[UITextField alloc]init];
        _txtNewPrice.layer.masksToBounds = YES;
        _txtNewPrice.layer.cornerRadius = 5.f;
        _txtNewPrice.layer.borderColor = theme_line_color.CGColor;
        _txtNewPrice.layer.borderWidth = 1.f;
        _txtNewPrice.delegate = self;
        _txtNewPrice.font =[UIFont systemFontOfSize:14.f];
        _txtNewPrice.textColor =[UIColor colorWithRed:125/255.f green:125/255.f blue:125/255.f alpha:1.0];
    }
    return _txtNewPrice;
}

-(UILabel *)labelTip{
    if(!_labelTip){
        _labelTip = [[UILabel alloc]init];
        _labelTip.font = [UIFont systemFontOfSize:14.f];
        _labelTip.textColor = [UIColor redColor];
        _labelTip.textAlignment = NSTextAlignmentCenter;
        _labelTip.text =  @"";
    }
    return _labelTip;
}

-(UIButton *)btnConfirm{
    if(!_btnConfirm){
        _btnConfirm = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btnConfirm setBackgroundImage:[UIImage imageNamed: @"bg-store-btn-red"] forState:UIControlStateNormal];
        [_btnConfirm setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_btnConfirm setTitle: @"确认修改" forState:UIControlStateNormal];
        [_btnConfirm addTarget:self action:@selector(confirmTouch:) forControlEvents:UIControlEventTouchUpInside];
        _btnConfirm.layer.masksToBounds = YES;
        _btnConfirm.layer.cornerRadius = 5.f;
        _btnConfirm.layer.borderColor = theme_line_color.CGColor;
        _btnConfirm.layer.borderWidth = 1.f;
    }
    return _btnConfirm;
}

-(UIButton *)btnCancel{
    if(!_btnCancel){
        _btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btnCancel setBackgroundImage:[UIImage imageNamed: @"bg-store-btn-gray"] forState:UIControlStateNormal];
        [_btnCancel setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_btnCancel setTitle: @"取消" forState:UIControlStateNormal];
        [_btnCancel addTarget:self action:@selector(cancelTouch:) forControlEvents:UIControlEventTouchUpInside];
        _btnCancel.layer.masksToBounds = YES;
        _btnCancel.layer.cornerRadius = 5.f;
        _btnCancel.layer.borderColor = theme_line_color.CGColor;
        _btnCancel.layer.borderWidth = 1.f;
    }
    return _btnCancel;
}


-(NSMutableArray *)arrayData{
    if(!_arrayData){
        _arrayData = [[NSMutableArray alloc]init];
    }
    return _arrayData;
}

-(NetPage *)page{
    if(!_page){
        _page = [[NetPage alloc]init];
        _page.pageIndex = 1;
    }
    return _page;
}

@end
